/*
 * 
 * time： 2018/12/28
 * desc: 主页
 * 
 * */

/*
 * 
 * time： 2018/12/28
 * desc: 导航栏组件
 * 
 * */
layui.use(['element', 'layer'], function() {
	var element = layui.element,
		layer = layui.layer;

	//首页欢迎光临和查看更多信息

	$.post(requestUrl.baseUrl + requestUrl.apiUrl.homeInfo, function(data) {
		if(data.code == 0) {
			$('#aboutUsCntent').text(data.page.list[1].content)
		}
	})


});

$(function() {
	//新闻列表

	$.post(requestUrl.baseUrl + requestUrl.apiUrl.newsList, {
		type: '公司新闻',
		page: '1',
		limit: '2'
	}, function(data) {
		if(data.code == 0) {
			var list = data.page.list
			for(var i = 0; i < list.length; i++) {
				var title = list[i].title;
				var id = list[i].id;
				getNewsImage(id)
				var createTime = list[i].createTime.substring(0, 10);;
				$('#companyNews').append('<div class="news-list layui-row" id="' + id + '">' +
					'<div class="news-list-img layui-col-md3">' +
					'<img src="" />' +
					'</div>' +
					'<div class="news-list-detail layui-col-md9">' +
					'	<div class="news-list-detail-content">' + title + '</div>' +
					'<div class="news-list-detail-time">' + createTime + '</div>' +
					'</div>' +
					'</div>')
			}
		}
	})
	$.post(requestUrl.baseUrl + requestUrl.apiUrl.newsList, {
		type: '行业新闻',
		page: '1',
		limit: '2'
	}, function(data) {
		if(data.code == 0) {
			var list = data.page.list
			for(var i = 0; i < list.length; i++) {
				var title = list[i].title;
				var id = list[i].id;
				getNewsImage(id)
				var createTime = list[i].createTime.substring(0, 10);
				$('#industryNews').append('<div class="news-list layui-row" id="' + id + '">' +
					'<div class="news-list-img layui-col-md3">' +
					'<img src="" />' +
					'</div>' +
					'<div class="news-list-detail layui-col-md9">' +
					'	<div class="news-list-detail-content">' + title + '</div>' +
					'<div class="news-list-detail-time">' + createTime + '</div>' +
					'</div>' +
					'</div>')
			}
		}
	})

	$('#news').on('click', '.news-list ', function() {

		var id = $(this).attr('id')
		location.href = requestUrl.httpUrl + 'html/aboutUs/newsDetail.html?id=' + id
	})

	function getNewsImage(id) {
		$.post(requestUrl.baseUrl + requestUrl.apiUrl.getImage, {
			recordId: id,
			attachType: 'NEWS_TITLE_PIC_1803'
		}, function(data) {
			if(data.code == 0 && data.list.length > 0) {
				$('#' + id).find('img').attr('src', data.list[0].url)
			}
		})
	}

	//产品列表
	$.get(requestUrl.baseUrl + requestUrl.apiUrl.producttype, function(data) {
		if(data.code == 0) {

			var list = data.list;
			for(var i = 0; i < list.length; i++) {
				var id = list[i].id;
				var productName = list[i].name;
				var unique = list[i].url.substring(26)
				getImage(id, productName, unique)
			}

		}
	})

	function getImage(id, productName, unique) {
		$.post(requestUrl.baseUrl + requestUrl.apiUrl.getImage, {
			recordId: id,
			attachType: 'PROJECT_COOPERATION_PIC_702'
		}, function(data) {
			if(data.code == 0 && data.list.length > 0) {

				$('#product_1').append('<div class="product-list-box" id="' + unique + '">' +
					'<div class="show-product-list">' +
					'<a href="#">' +
					'<img src="' + data.list[0].url + '"/>' +
					'<span>' + productName + '</span>' +
					'<span class="arrow"></span>' +
					'</a>' +
					'</div>' +
					'</div>')
			}
		})
	}
	
	$('#product_1').on('click', '.product-list-box', function(){
		var id = $(this).attr('id')
		location.href = requestUrl.httpUrl + 'html/product/product.html#' + id
	})
	

})